﻿using DependencyInjectionHelperLib.Attributes;
using MeterReader.Models;

namespace MeterReader.Services.Repositories
{
    [DIRegistration(interfaceTypes:typeof(IWriteDbRepository))]
    public class MeterWriteRepository : IWriteDbRepository
    {
        private readonly MeterDBContext _dbContext;

        public MeterWriteRepository(MeterDBContext dbContext)
        {
            _dbContext = dbContext;
        }

        public async Task WriteDataAsync(TableMeters tableMeters, CancellationToken cancellationToken)
        {
            await _dbContext.TMeters!.AddAsync(tableMeters, cancellationToken);
            await _dbContext.SaveChangesAsync(cancellationToken);
        }
    }
}